其他
线性相关回归之R语言实现
> x1 <- c(9.9, 11.2, 9.4, 8.4, 14.8, 12.4, 13.1, 13.4, 11.2, 9.5, 10.7, 9.2)
> x2 <- c(7.9, 8.9, 8.5, 9.4, 12, 11.5, 14.5, 12.3, 9.2, 11, 8.3, 8.5)
> plot(x2 ~ x1, pch = 16) > summary(model)
Call:
lm(formula = x2 ~ x1)
Residuals:
Min 1Q Median 3Q Max
-1.5658 -1.1169 -0.3129 0.6186 2.8291
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.8182 2.5775 0.705 0.49664
x1 0.7521 0.2289 3.285 0.00821 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.495 on 10 degrees of freedom
Multiple R-squared: 0.5191, Adjusted R-squared: 0.471
F-statistic: 10.79 on 1 and 10 DF, p-value: 0.008214
> res <- residuals(model) ##生成残差
> shapiro.test(x1)
Shapiro-Wilk normality test
data: x1
W = 0.94989, p-value = 0.6354> shapiro.test(res)
Shapiro-Wilk normality test
data: res
W = 0.90737, p-value = 0.1974
再来一例看看!!!